import React, { Component } from 'react';

class CounterButton extends Component {
  render() {
    const {decerment} = this.props

    return (
      <button onClick={ decerment }>-1</button>
    )
  }
}

export default class App extends Component {
  constructor(props) {
    super(props)

    this.state = {
      counter: 0
    }
  }

  render() {
    return (
      <div>
       <h2>current count：{this.state.counter}</h2> 
       <button onClick={ e => this.increment() }>+1</button>
       <CounterButton decerment={ e => this.decerment() } />
      </div>
    )
  }

  increment() {
    this.setState({
      counter: this.state.counter + 1
    })
  }

  decerment() {
    this.setState({
      counter: this.state.counter - 1
    })
  }
}